#!/bin/sh

# Verify that no original content remains after a scrub,
# with and without signature

unset TMPDIR # messes up diff if not /tmp

TEST=t14
TESTFILE=${TMPDIR:-/tmp}/scrub-$TEST
TESTFILE2=${TMPDIR:-/tmp}/scrub-zero-$TEST

# needs to be a multiple of file system blocksize to avoid round-up
FILESIZE=4M

DATAPAT=0xbe

rm -f $TESTFILE $TESTFILE2 $TEST.out

(for pattern in bsi,0x7f dod,0xff nnsa,0 fastold,0x55 old,0x55; do
	patstr=`echo $pattern | cut -d, -f1`
	patbyte=`echo $pattern | cut -d, -f2`

	./pat -S -p $DATAPAT -s $FILESIZE >$TESTFILE
	$PATH_SCRUB -S -p $patstr $TESTFILE || exit 1
	echo "Verifying $patstr last pass $patbyte without signature"
	./pat -S -p $patbyte -s $FILESIZE >$TESTFILE2
	cmp $TESTFILE $TESTFILE2 || exit 1

	./pat -S -p $DATAPAT -s $FILESIZE >$TESTFILE
	$PATH_SCRUB -p $patstr $TESTFILE || exit 1
	echo "Verifying $patstr last pass $patbyte with signature"
	./pat -p $patbyte -s $FILESIZE >$TESTFILE2
	cmp $TESTFILE $TESTFILE2 || exit 1
done) >> $TEST.out 2>&1

rm -f $TESTFILE $TESTFILE2
diff $TEST.out $TEST.exp >$TEST.diff
